<?php
$sql="SELECT a.*, upper(b.cNentidad) as entidad, upper(c.cNmunicipio) as municipio,r.fSintoma_inicial,fIngreso,
	r.id_principal as id_evento,catalogos.dbo.fUnidad_proced(r.id_sector,r.id_unidad) as cUnidad
	FROM dat_generales a
	INNER JOIN  dat_registro r ON (a.id_principal = r.id_generales)
	LEFT JOIN catalogos.dbo.entidades_inegi b on (a.nEntidad = b.id_entidad) 
	LEFT JOIN catalogos.dbo.municipios_inegi c on (a.nMunicipio = c.id_principal)
	WHERE r.id_principal=$datos[idr]
";
$qry=mssql_query($sql,$link) or die(mssql_get_last_message());
$r=mssql_fetch_array($qry);

?>


<table width="750" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f3f3f3" class="datos cuadro2">
  <tr bgcolor="F8B145">
    <td height="23" colspan="5" align="center"><div align="center"><span class="datos" style="font-weight: bold">DATOS GENERALES DEL PACIENTE</span></div></td>
  </tr>
  <tr>
    <td width="136">NOMBRE COMPLETO:</td>
    <td width="298"><b><?php echo $r['cNombre']; ?> <?php echo $r['cPaterno']; ?> <?php echo $r['cMaterno']; ?></b></td>
    <td width="34">SEXO:</td>
    <td width="95"><b>
	<?php
		 echo ($r['nSexo']==1?"HOMBRE":"MUJER"); 
		if($r['nSexo']==2 and $r['nMesesE'] > 0) echo " &nbsp;CON ".$r['nMesesE']." MESES DE EMBARAZO";	 
	?></b></td>
    <td width="187">FECHA DE NAC.:<b><?php echo $r['nDias']."/".$r['nMeses']."/".$r["nAnio"]; ?></b></td>
  </tr>
  <tr>
    <td>UNIDAD M&Eacute;DICA:&nbsp;</td>
    <td colspan="3"><b><?php echo $r['cUnidad']; ?></b></td>
    <td>CURP:<b><?php echo $r['curp']; ?></b></td>
  </tr>
  <tr>
    <td colspan="5"><table width="100%" border="0" cellspacing="1" cellpadding="1">
      <tr>
        <td>INICIO DE SINTOMAS:<b><?php echo convertdate5($r['fSintoma_inicial']); ?></b></td>
        <td>&nbsp;</td>
        <td>FECHA DE LA MUESTRA:<b><?php echo convertdate5($r['fIngreso']); ?></b></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2">SINTOMAS:<span class="datos"><b>
          <?php
		$sql = "select b.sintoma from aux_sintomas a 
		left join cat_sintomas b on (a.id_sintoma = b.id_sintomas ) 
		where a.id_registro = $r[id_evento] and id_decision = 1";
//	echo $sq8;
		$r1 = mssql_query ($sql,$link);
		$cadena = "";
		while($rep = mssql_fetch_array($r1)){
			$cadena .= $rep['sintoma'].", ";
		}
		echo substr($cadena,0,-2);
	?>
        </b></span></td>
        <td colspan="2">CO-MORBILIDAD:<span class="datos"><b>
          <?php $sql = "select b.diagnostico from aux_Diagnosticos a 
			left join cat_diagnosticos b on (a.id_diagnostico = b.id_diagnostico ) 
			where a.id_registro = $r[id_evento] and id_decision = 1 and b.nTipo=3";
		$r2 = mssql_query ($sql,$link);
		$cadena = "";
		while($rep2 = mssql_fetch_array($r2)){
			$cadena .= $rep2['diagnostico'].", ";
		}
		echo substr($cadena,0,-2);
	?>
        </b></span></td>
        </tr>
    </table></td>
  </tr>
</table>